
"""
    权限
"""

from users.models import Permission
from users.serialiaers import permission
from utils.model_view_set import CustomModelViewSet
from utils.tree import TreeAPIView, TreeAPIFormView


class PermissionModelView(TreeAPIFormView, CustomModelViewSet):
    """
    权限管理：增删改查
    """
    perms_map = ({'*': 'admin'}, {'*': 'permission_all'}, {'get': 'permission_list'}, {'post': 'permission_create'},
                 {'put': 'permission_edit'}, {'delete': 'permission_delete'})
    queryset = Permission.objects.all().exclude(method='admin')
    serializer_class = permission.PermissionModelSerializer
    search_fields = ('name', 'method',)  # 已在全局设置：指定字段模糊搜索


class PermissionModelTreeView(TreeAPIView):
    """
    权限树
    """
    queryset = Permission.objects.all().exclude(method='admin')

